﻿
function pushItems(saveContent, itemsStr, type) {
    let saveJson = JSON.parse(saveContent);
    let items = JSON.parse(itemsStr);
    console.log(items);
    let player = saveJson[type === 0 ? 'autoSaveData' : 'rogueSaveData'];
    items.forEach(item => {
        for (let k in item.data) {

            if (player.pickupHistory.indexOf(item.id) == -1) {

                switch (k) {
                    case "statusEffects":
                        let itemEffect;
                        if (typeof (item.data.statusEffects) === "string") {
                            itemEffect = {
                                "id": item.data.statusEffects,
                                "level": 0,
                                "duration": -1.0,
                                "durationRatio": 0.0,
                                "userData": 0,
                                "userString": "",
                                "sticky": false
                            };
                        } else {
                            itemEffect = item.data;
                        }
                        player.statusEffects.push(itemEffect);
                        break;
                    default: 
                        player[k] = item.data[k];
                        break;
                }
                player.dropHistory.push(item.id);
                player.pickupHistory.push(item.id);
            }
        }
    });
    return JSON.stringify(saveJson);
}
function fillBombKey(saveContent, type) {
    let saveJson = JSON.parse(saveContent);
    let player = saveJson[type === 0 ? 'autoSaveData' : 'rogueSaveData'];
    player.bombs = 99;
    player.keys = 99;
    return JSON.stringify(saveJson);
}